package Utils;

import java.util.List;

public class PageUitls <T>{
    public PageUitls(int totalCount, int pageSize, String currentPage) {
        this.totalCount = totalCount;
        this.pageSize = pageSize;
        initCurrentPage(currentPage);
        initTotalPage();
        initStartIndex();
        initPrePage();
        initNextPage();
    }
    private void initCurrentPage(String currentPage){
        if (currentPage==null){
            this.currentPage=1;
        }else {
            this.currentPage=Integer.parseInt(currentPage);
        }
    }
    private void initTotalPage(){
        this.totalPage=
                (totalCount%pageSize==0)?(totalCount/pageSize):(totalCount/pageSize+1);
    }
    private void initStartIndex(){
        this.startIndex=(currentPage-1)*pageSize;
    }
    private void initPrePage(){
        if(this.currentPage==1){
            this.prePage=1;
        }else {
            this.prePage= this.currentPage - 1;
        }
    }
    private  void initNextPage(){
        if (this.currentPage==this.totalPage){
            this.nextPage=this.totalPage;
        }else {
            this.nextPage=this.currentPage+1;
        }
    }

    private int totalCount;//总记录数
    private int pageSize;//页容量
    private int currentPage;//当前页码
    private int totalPage;//总页数
    private int startIndex;//每页第一条记录的起始下标
    private int prePage;//上一页
    private int nextPage;//下一页
    private List<T>list;
    public List<T>getList(){
        return list;
    }
    public void setList(List<T> list) {
        this.list = list;
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public int getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public int getStartIndex() {
        return startIndex;
    }

    public void setStartIndex(int startIndex) {
        this.startIndex = startIndex;
    }

    public int getPrePage() {
        return prePage;
    }

    public void setPrePage(int prePage) {
        this.prePage = prePage;
    }

    public int getNextPage() {
        return nextPage;
    }

    public void setNextPage(int nextPage) {
        this.nextPage = nextPage;
    }
}
